/*
============================================================================
 Name        : dd_test.c
 Author      : Jian (raphyer@hotmail.com)
 Version     :
 Copyright   : GPL
 Description : dd_test.c - source file
============================================================================
*/

/* INCLUDE FILES */
#include "dd_test.h"

#include "dd_vector.h"
#include "dd_stack.h"
#include "dd_btree.h"
#include "dd_avl.h"
#include "dd_rbtree.h"
#include "dd_bheap.h"
#include "dd_queue.h"
#include "dd_dtable.h"
#include "dd_fixed_queue.h"

#include "dd_log.h"
#include "sd_platform.h"


#ifdef __DD_TEST

DD_BOOL dd_test() 
{
	dd_log_keypath("dd_test start the UNIT TEST") ;

	if (!dd_vector_test()) {
		dd_log_keypath("dd_vector_test test FAILED") ;
		return DD_FALSE ;
	}
	dd_log_keypath("dd_vector_test test SUCCEED") ;

    if (!dd_stack_test()) {
        dd_log_keypath("dd_stack_test test FAILED") ;
        return DD_FALSE ;
    }
	dd_log_keypath("dd_stack_test test SUCCEED") ;
    
    if (!dd_queue_test()) {
        dd_log_keypath("dd_queue_test test FAILED") ;
        return DD_FALSE ;
    }
	dd_log_keypath("dd_queue_test test SUCCEED") ;
    
    if (!dd_btree_test()) {
        dd_log_keypath("dd_btree_test test FAILED") ;
        return DD_FALSE ;
    }
    dd_log_keypath("dd_btree_test test SUCCEED") ;

    if (!dd_avl_test()) {
        dd_log_keypath("dd_avl_test test FAILED") ;
        return DD_FALSE ;
    }
	dd_log_keypath("dd_avl_test test SUCCEED") ;

    if (!dd_rbtree_test()) {
        dd_log_keypath("dd_rbtree_test test FAILED") ;
        return DD_FALSE ;
    }
	dd_log_keypath("dd_rbtree_test test SUCCEED") ;

    if (!dd_bheap_test()) {
        dd_log_keypath("dd_bheap_test test FAILED") ;
        return DD_FALSE ;
    }
	dd_log_keypath("dd_bheap_test test SUCCEED") ;
    
    if (!dd_dtable_test()) {
        dd_log_keypath("dd_dtable_test test FAILED") ;
        return DD_FALSE ;
    }
	dd_log_keypath("dd_dtable_test test SUCCEED") ;
    
    if (!dd_fqueue_test()) {
        dd_log_keypath("dd_fqueue_test test FAILED") ;
        return DD_FALSE ;
    }
    dd_log_keypath("dd_fqueue_test test SUCCEED") ;

	dd_log_keypath("dd_test the UNIT TEST is SUCCEED") ;

	return DD_TRUE ;
}

static sd_time testTime = {0} ;

void dd_test_time_start(const char* task_msg) 
{
    memset(&testTime, 0, sizeof(sd_time)) ;
    sd_get_cur_time(&testTime) ;    

    dd_log_keypath("===== Start to count %s =====\n", task_msg) ;
}

void dd_test_time_end(const char* task_msg) 
{
    sd_time curTime = {0} ;
    
    sd_get_cur_time(&curTime) ;

    if (curTime.usecond >= testTime.usecond)
        dd_log_keypath("===== End to count %s diff second = %d and usecond = %d =====\n", task_msg, curTime.second - testTime.usecond, curTime.usecond - testTime.usecond) ;
    else 
        dd_log_keypath("===== End to count %s diff second = %d and usecond = %d =====\n", task_msg, curTime.second - 1 - testTime.usecond, curTime.usecond + 1000 * 1000 - testTime.usecond) ;
    
    testTime = curTime ;
}


#else

DD_BOOL dd_test() 
{
	return DD_TRUE ;
}

void dd_test_time_start(const char* task_msg) 
{
    
}

void dd_test_time_end(const char* task_msg) 
{
    
}

#endif	/* __DD_TEST */


/* End of File */





















